package vip.xiaonuo.modular.utils;

import cn.hutool.dfa.WordTree;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

import java.util.List;

/**
 * @author liu
 */
public class SensitiveFilterUtil {

    public static String filter(String text, String filePath) {
        ExcelReader reader = ExcelUtil.getReader(filePath);
        List<List<Object>> readAll = reader.read();
        WordTree tree = new WordTree();
        for (List<Object> list : readAll) {
            String s = list.get(0).toString();
            tree.addWord(s);
        }
        List<String> matchAll = tree.matchAll(text, -1, true, true);
        for (String s : matchAll) {
            text = text.replace(s, "*");
        }

        return text;
    }
}
